package com.fansm.framework.beans.factory.support;

import com.fansm.framework.beans.factory.config.BeanDefinition;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 注册表管理所有的bean信息
 * @author fansm
 * @date 2024/4/15
 */
public class SimpleBeanDefinitionRegistry implements BeanDefinitionRegistry {
    private final Map<String, BeanDefinition> beanDefinitionMap = new ConcurrentHashMap<>(64);
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        this.beanDefinitionMap.put(beanName, beanDefinition);
    }

    public void removeBeanDefinition(String beanName) {

    }

    public BeanDefinition getBeanDefinition(String beanName) {
        return this.beanDefinitionMap.get(beanName);
    }


    public boolean containsBeanDefinition(String beanName) {
        return this.beanDefinitionMap.containsKey(beanName);
    }

    public String[] getBeanDefinitionNames() {
        Set<String> strings = this.beanDefinitionMap.keySet();
        String[] ans = new String[strings.size()];
        int index = 0;
        for (String ele : strings) {
            ans[index] = ele;
            index++;
        }
        return ans;
    }

    public int getBeanDefinitionCount() {
        return this.beanDefinitionMap.size();
    }
}
